package service

import (
	"context"
	"errors"
	__ "user-srv/basic/proto"
	"user-srv/handler/dao"
)

// 人脸注册
func (s *Server) RegisterFace(_ context.Context, in *__.RegisterFaceReq) (*__.RegisterFaceResp, error) {
	err := dao.AddFaceByUserId(int32(in.Userid), in.FaceImg)
	if err != nil {
		return nil, errors.New("人脸注册失败")
	}
	return &__.RegisterFaceResp{Faceid: in.Userid}, nil
}

// 人脸登录
func (s *Server) LoginFace(_ context.Context, in *__.LoginFaceReq) (*__.LoginFaceResp, error) {
	if in.FaceImg == "" {
		return nil, errors.New("图片参数不能为空")
	}
	face, err := dao.Face(in.FaceImg)
	if err != nil {
		return nil, errors.New("人脸识别失败")
	}
	return &__.LoginFaceResp{Userid: int64(face)}, nil
}
